<?php
class C_usergroups extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_usergroups');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$data["s_menus"] = $this->m_usergroups->s_menus();
				$this->load->view('v_usergroups',$data);
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['groups_name'] = nosql_post("groups_name");
		$data['groups_desc'] = nosql_post("groups_desc");
		echo $this->m_usergroups->_list($data);
	}
	
	function _insert(){
		$menu = ($this->input->post('menu'));
		$data = array(
			'groups_name' => $this->input->post('groups_name'), 
			'groups_desc' => $this->input->post('groups_desc'), 
			  
			'groups_active'=> 'y');
		$this->m_usergroups->_insert($data,$menu );
		echo 1;
	}
	
	function _update(){
		$menu = ($this->input->post('menu'));
		$groups_id = $this->input->post('groups_id');
		$data = array(
			'groups_name' => $this->input->post('groups_name'), 
			'groups_desc' => $this->input->post('groups_desc'), 
			);
		$this->m_usergroups->_update($data,$groups_id,$menu );
		echo 1;
 	}
	
	function _delete(){
		$groups_id= $this->input->post('groups_id');
		$data = array(
			'groups_active' => 'n'
		);
		$this->m_usergroups->_delete($data,$groups_id);
		echo 1;
	}
}